package com.dshore.messagecenter.service.warning.impl;


import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.dshore.messagecenter.dao.warning.WarningPersonDao;
import com.dshore.messagecenter.model.system.ResponseResult;
import com.dshore.messagecenter.model.system.User;
import com.dshore.messagecenter.model.warning.MrWarningPerson;
import com.dshore.messagecenter.service.warning.WarningPersonService;
import com.dshore.messagecenter.util.Page;





@Service
public class WarningPersonServiceImpl implements WarningPersonService{
	@Autowired
	private WarningPersonDao warningPersonDao;
	
	@Value("${project_name}")
	private String projectName;
	/**
	 * 展示预警人员信息
	 */
	public Page<MrWarningPerson> queryListAll(MrWarningPerson warningPerson) {
		// 总记录数
		long total = warningPersonDao.queryCountByPrama(warningPerson);
		// 模糊查询
		List<MrWarningPerson> list = warningPersonDao.queryListByPrama(warningPerson);
		// 重构对象,方便扩展
			Page<MrWarningPerson> page = new Page<MrWarningPerson>(warningPerson.getLimit(), total, warningPerson.getOffset(),list);
			return page;
		}
	/**
	 * 获取单个信息
	 */
	public MrWarningPerson getById(String id) {		
		return warningPersonDao.getById(id);
	}
	/**
	 * 新增
	 */
	@Override
	public ResponseResult<Void> addWarningPerson(MrWarningPerson warningPerson) {
		ResponseResult<Void>responseResult=new ResponseResult<Void>(200, "新增成功");
		Integer i=warningPersonDao.addWarningPerson(warningPerson);
		if(i<=0) {
			responseResult.setState(400);
			responseResult.setMessage("新增失败");
		}
		return responseResult;
	}
	/**
	 * 修改
	 */
	@Override
	public ResponseResult<Void> changeWarningPerson(MrWarningPerson warningPerson) {
		ResponseResult<Void>responseResult=new ResponseResult<Void>(200, "修改成功");
		Integer i=warningPersonDao.changeWarningPerson(warningPerson);
		if(i<0) {
			responseResult.setState(400);
			responseResult.setMessage("修改失败");
		}
		return responseResult;
	}
	/**
	 * 删除
	 */
	@Override
	public ResponseResult<Void> deleteByIds(String ids) {
		ResponseResult<Void>responseResult=new ResponseResult<Void>();
		String[] idArr = ids.split(",");
		List<Map<String, Object>> list = warningPersonDao.selectWarningThresholds(idArr);
		if(list.size()>0) {
			responseResult.setState(400);
			responseResult.setMessage("删除失败！预警阈值设置含有删除的人员");
			return responseResult;
		}else {
			warningPersonDao.deleteByIds(idArr);
			responseResult.setState(200);
			responseResult.setMessage("删除成功");
			return responseResult;
		}
		
	}
	/**
	 * 
	 */
	@Override
	public List<User> getAccount() {
		// TODO Auto-generated method stub
		return null;
	}
	
	/*public List<User> getAccount() {
		AppframeOrg appframeorg= AppframeOrgClient.getInstance();
		List<User> list =new ArrayList<User>();	
		//取GJJZSTYXXZX对应的业务系统信息
				SysSystem system = appframeorg.getSystemByCode(projectName);
				//查询业务角色分组信息
				SysRoleGroup[] group =appframeorg.getRoleGroupsBySystem(system.getId());
				for(int i=0;i<group.length;i++) {
					//查询业务角色信息
					SysRole[] roles = appframeorg.getRolesByGroup(system.getId(),group[i].getId());					
					for(int t=0;t<roles.length;t++) {
						// 取某个角色的业务组织单元角色列表
						SysSpRole[]spRole=appframeorg.getSpRolesByRole(roles[t].getId());
						for(int p=0;p<spRole.length;p++) {
							User[] users = appframeorg.getUsersBySpRole(spRole[p].getId());
							for(int r=0;r<users.length;r++) {
								list.add(users[i]);
							}
						}		
					}
				}
				return list;
	  }
*/
	
}




